//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package pxb.android.zipalign;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.zip.ZipException;

public final class FastZipEntry {
    public byte[] name;
    public long crc = -1L;
    public long compressedSize = -1L;
    public long unCompressSize = -1L;
    public int compressionMethod = -1;
    public long modTime = -1L;
    public int gpbf = 0;
    public long localHeaderRelOffset = -1L;
    public static final int DEFLATED = 8;
    public static final int STORED = 0;

    public String utf8Name() {
        return new String(this.name, StandardCharsets.UTF_8);
    }

    public FastZipEntry clone() {
        FastZipEntry n = new FastZipEntry();
        n.name = this.name;
        n.crc = this.crc;
        n.compressedSize = this.compressedSize;
        n.unCompressSize = this.unCompressSize;
        n.compressionMethod = this.compressionMethod;
        n.modTime = this.modTime;
        n.gpbf = this.gpbf;
        n.localHeaderRelOffset = this.localHeaderRelOffset;
        return n;
    }

    public FastZipEntry() {
    }

    public void setTime(Date d) {
        int year = d.getYear() + 1900;
        long dostime = (long)(year - 1980 << 25 | d.getMonth() + 1 << 21 | d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 | d.getSeconds() >> 1);
        this.modTime = dostime + (d.getTime() % 2000L << 32);
    }

    FastZipEntry(ByteBuffer it0) throws IOException {
        ByteBuffer it = (ByteBuffer)it0.slice().order(ByteOrder.LITTLE_ENDIAN).limit(46);
        FastZipIn.skip(it0, 46);
        int sig = it.getInt();
        if ((long)sig != 33639248L) {
            throw new ZipException("Central Directory Entry signature not found; was " + String.format("0x%08x", sig));
        } else {
            it.position(8);
            this.gpbf = it.getShort() & '\uffff' & 2048;
            this.compressionMethod = it.getShort() & '\uffff';
            this.modTime = (long)it.getInt() & 4294967295L;
            this.crc = (long)it.getInt() & 4294967295L;
            this.compressedSize = (long)it.getInt() & 4294967295L;
            this.unCompressSize = (long)it.getInt() & 4294967295L;
            if (this.compressionMethod == 0 && this.compressedSize != this.unCompressSize) {
                throw new ZipException("fai compress");
            } else {
                int nameLength = it.getShort() & '\uffff';
                int extraLength = it.getShort() & '\uffff';
                int commentByteCount = it.getShort() & '\uffff';
                it.position(42);
                this.localHeaderRelOffset = (long)it.getInt() & 4294967295L;
                byte[] nameBytes = new byte[nameLength];
                it0.get(nameBytes);
                this.name = nameBytes;
                if (extraLength > 0) {
                    FastZipIn.skip(it0, extraLength);
                }

                if (commentByteCount > 0) {
                    FastZipIn.skip(it0, commentByteCount);
                }

            }
        }
    }

    public void setUtf8Name(String name) {
        this.name = name.getBytes(StandardCharsets.UTF_8);
        this.gpbf = 2048;
    }
}
